package com.bj58.mis.apm.server.kylin.call;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Random;

public class KylinCall extends BaseCall{

    public KylinCall(String projectName, int thread, int loop) {
        super(projectName, thread, loop);
    }

    public static void main(String[] args) throws Exception {
        new KylinCall("rocmonitor", 2, 1000);
    }

    public final Random random = new Random();

    @Override
    public void query(Connection conn) throws Exception{
        String[] sqls = {"select c.name,log.md5,sum(log.duration) from O_M_KYLIN_QUERY_LOG log left join O_M_KYLIN_CUBE c on log.cube_id = c.id group by c.name,log.md5",
                        "select log.host,log.cube_id,c.name,sum(log.duration),count(1) from O_M_KYLIN_QUERY_LOG log left join O_M_KYLIN_CUBE c on log.cube_id = c.id group by log.host,log.cube_id,c.name",
                        "select log.project_id,log.cube_id,c.name,sum(log.duration),count(1) from O_M_KYLIN_QUERY_LOG log left join O_M_KYLIN_CUBE c on log.cube_id = c.id group by log.project_id,log.cube_id,c.name",
                        "select log.cube_id,c.name,log.dt,sum(log.duration),count(1) from O_M_KYLIN_QUERY_LOG log left join O_M_KYLIN_CUBE c on log.cube_id = c.id group by log.cube_id,c.name,log.dt"};
        PreparedStatement state = conn.prepareStatement(sqls[random.nextInt(sqls.length)]);
        ResultSet resultSet = state.executeQuery();
        int i = 0;
        while(resultSet.next()){
            i ++;
        }
        state.close();
        System.out.println("====>>>>  result size is " + i);
    }
}
